home *** CD-ROM | disk | FTP | other *** search
- /* LUSETUP.C allows you to set colors and hotkeys for INTERCOM and
- some versions of Artisoft's LANPUP utility. Although I'm including
- source for LUSETUP, it requires a proprietary video library which
- I cannot distribute. This source code contains the proper techniques
- and addresses for changing colors and hotkeys, so you should be able
- to adapt it for whatever video library you prefer. */
-
-
- /* now being used to set colors and hotkeys */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
-
- #include <\c\io\screenio.h>
- #include <\c\io\iowin.h>
- #include <\c\io\keyboard.h>
-
- /* aaargh! Define all the scan codes for the standard kbd_table */
- char *kbd_table[] = {"","1","2","3","4","5","6","7","8","9","0","-","=","",
- "","q","w","e","r","t","y","u","i","o","p","[","]","",
- "","a","s","d","f","g","h","j","k","l",";","'",
- "","","\\","z","x","c","v","b","n","m",",",".","/","",
- ""," ","" };
-
- #define NUM_KEYCODES 59
-
- FIELD screen[] = {
- {2,3,32,MENU_ITEM,0,NULL,3,1,3,1,NULL,NULL,NULL,NULL},
- {3,3,32,MENU_ITEM,0,NULL,0,2,0,2,NULL,NULL,NULL,NULL},
- {4,3,32,MENU_ITEM,0,NULL,1,3,1,3,NULL,NULL,NULL,NULL},
- {5,3,32,MENU_ITEM,0,NULL,2,0,2,0,NULL,NULL,NULL,NULL}
- };
-
- int toggles[4] = {0,0,0,0};
- int members[4] = {0,1,2,3};
- char hotkey[10];
-
- FIELD kscreen[] = {
- {7, 10,15,TOGGLE_FIELD,1,&members[0],3,1,4,4,NULL,NULL,NULL,(char *) &toggles[0]},
- {8, 10,15,TOGGLE_FIELD,1,&members[1],0,2,4,4,NULL,NULL,NULL,(char *) &toggles[1]},
- {9, 10,15,TOGGLE_FIELD,1,&members[2],1,3,4,4,NULL,NULL,NULL,(char *) &toggles[2]},
- {10,10,15,TOGGLE_FIELD,1,&members[3],2,3,4,4,NULL,NULL,NULL,(char *) &toggles[3]},
- {7,40,1, TEXT_FIELD, 0,NULL,3,0,0,0,NULL,NULL,NULL,hotkey}
- };
-
- #define IROW 5
- #define ICOL 8
- #define ILENGTH 5
- #define IWIDTH 63
- #define BC 112
- #define FC 7
-
- #define M_COLOR_LOC 9 /* message's color patch location */
-
- #define I_COLOR_LOC 139 /* intercom's color patch location */
- #define I_HOTKEY_LOC 140 /* intercom's hotkey patch location */
- #define I_SHIFT_STATE 141 /* intercom's shift state info */
-
- #define L_HOTKEY_LOC 1196 /* lanpup's hotkey location */
- #define L_SHIFT_STATE 1197 /* lanpup's shift state byte */
-
- #define ATTRIB (background * 16) + foreground
- #define ERRLOC 5,20
-
- extern VIDEO_PARMS VIDEO;
- extern WINDOW_COLORS COLORS;
- extern int field_column;
-
- /* find_code ****************************************************************
- *****************************************************************************/
- int find_code(key)
- char key;
- {
- int i;
-
- for (i = 0; i < NUM_KEYCODES;i++) {
- if (key == *kbd_table[i]) return(i + 1);
- }
- return(FALSE);
-
- }
-
- /* patch ********************************************************************
- *****************************************************************************/
- patch(fname,location,newval)
- char *fname;
- long location;
- char newval;
- {
- FILE *file;
-
- file = fopen(fname,"r+b");
- if (file != NULL) {
- fseek(file,location,SEEK_SET);
- fwrite((char *) &newval,1,1,file);
- fclose(file);
- }
- }
-
- /* draw_screen **************************************************************
-
- *****************************************************************************/
- draw_screen() {
- char clr;
-
- cls();
-
- clr = (VIDEO.color) ? 31:15;
-
- wpaint(0,0,25,80,&clr,1);
-
- write_at(0,0,
- "LANutils Setup/Patch Utility Version 2.0 (C) Copyright 1990 by SoftMagic, Inc.",clr);
-
- shadow_box(1,1,7,37,NORMAL,DOUBLE_LINE);
- write_at(1,2,"Main Functions",NORMAL);
-
- write_at(2,3,"Change INTERCOM's screen colors",NORMAL);
- write_at(3,3,"Change MESSAGE's screen colors",NORMAL);
- write_at(4,3,"Change INTERCOM's activation key",NORMAL);
- write_at(5,3,"Change LANPUP's activation key",NORMAL);
-
-
- write_at(24,0,
- "Press Enter to select an option, Esc to quit",clr);
-
- }
-
- /* rpatch ********************************************************************
-
- *****************************************************************************/
- int rpatch(fname,location,newval)
- char *fname;
- long location;
- char *newval;
- {
- FILE *file;
-
- file = fopen(fname,"rb");
- if (file != NULL) {
- fseek(file,location,SEEK_SET);
- fread(newval,1,1,file);
- fclose(file);
- return(TRUE);
- }
- else return(FALSE);
- }
-
- /* set_color ********************************************************
-
- *****************************************************************************/
- set_color(fname,location)
- char *fname;
- unsigned int location;
- {
- unsigned int result,foreground,background,done;
- unsigned char cbyte;
- char string[40];
-
- result = rpatch(fname,(long) location,&cbyte);
-
- if (!result) {
- error(ERRLOC,"Unable to read file.",
- "Make sure it is in the current directory",
- "Then try again.",NULL);
- return;
- }
-
- foreground = cbyte % 16;
- background = cbyte / 16;
-
- save_scr(3,7,17,60);
- shadow_box(3,7,17,60,112,DOUBLE_LINE);
- sprintf(string,"Change screen colors for %s",fname);
- write_at(3,8,string,112);
-
- hline(10,8,57,SINGLE_LINE);
-
- write_at(12,12,"Up & Down arrows - Change the foreground color",112);
- write_at(13,12,"Left & Right arrows - Change the background color",112);
- write_at(14,12,"Home - Restore default colors",112);
- write_at(15,12,"Enter - Save changes and return",112);
- write_at(16,12,"Esc - Return without saving changes",112);
-
- done = FALSE;
- while (!done) {
- box(5,17,4,40,ATTRIB,DOUBLE_LINE);
- write_at(6,25,"Sample pop up window text",ATTRIB);
-
- switch (getkey()) {
- case Up: /* foreground color up */
- foreground = ++foreground % 16;
- break;
- case Dn: /* foreground color down */
- foreground--;
- if (foreground < 0) foreground = 16;
- break;
- case Left: /* background color down */
- background--;
- if (background < 0) background = 16;
- break;
- case Right: /* background color up */
- background = ++background % 16;
- break;
- case Home: /* restore defaults */
- foreground = 0;
- background = 7;
- break;
- case Ret: /* save and quit */
- done = TRUE;
- patch(fname, (long) location, ATTRIB);
- break;
- case Esc:
- done = TRUE;
- break;
- }
- }
- restore_scr();
- }
-
- /* set_hotkey ********************************************************
-
- *****************************************************************************/
- set_hotkey(fname,keyloc,shiftloc)
- char *fname;
- unsigned int keyloc,shiftloc;
- {
- unsigned int result,keycode,shift_status;
- int field,code,old_normal,old_hilite;
- char string[40];
-
- result = rpatch(fname,(long) keyloc,&keycode);
-
- if (!result) {
- error(ERRLOC,"Unable to read file.",
- "Make sure it is in the current directory",
- "Then try again.",NULL);
- return;
- }
-
- strcpy(kscreen[4].result,kbd_table[keycode - 1]);
-
- result = rpatch(fname,(long) shiftloc,&shift_status);
- *kscreen[3].result = (shift_status & 1);
- *kscreen[2].result = (shift_status & 2);
- *kscreen[1].result = (shift_status & 4);
- *kscreen[0].result = (shift_status & 8);
-
- old_normal = NORMAL;
- NORMAL = 112;
- old_hilite = HILITE;
- HILITE = 7;
-
- save_scr(3,7,18,46);
- shadow_box(3,7,18,46,112,DOUBLE_LINE);
- sprintf(string,"Change activation key for %s",fname);
- write_at(3,8,string,112);
-
- write_at(5,10,"Shift Status",BRIGHT);
- box(6,9,6,17,113,SINGLE_LINE);
- write_at(7,13,"Alt",112);
- write_at(8,13,"Ctrl",112);
- write_at(9,13,"Left shift",112);
- write_at(10,13,"Right shift",112);
-
- write_at(5,33,"Activation key",BRIGHT);
- box(6,33,3,15,113,SINGLE_LINE);
-
- hline(13,8,43,SINGLE_LINE);
-
- write_at(15,11,"Space - Select/deselect shift key",112);
- write_at(16,11,"Enter - Save changes and return",112);
- write_at(17,11,"Esc - Return without saving changes",112);
-
- field = code = 0;
- while (TRUE) {
- do_fields(kscreen,5,&field,&code);
- if (code == Esc) break;
- else if (code == Ret) {
- result = find_code(*kscreen[4].result);
- if (result) patch(fname,(long) keyloc,result);
- else {
- error(ERRLOC,"Sorry, I can't use that key to",
- "pop up. Pick another one and try",
- "again.",NULL);
- break;
- }
-
- result = (*kscreen[3].result) ? 1:0;
- result |= (*kscreen[2].result) ? 2:0;
- result |= (*kscreen[1].result) ? 4:0;
- result |= (*kscreen[0].result) ? 8:0;
- patch(fname,(long) shiftloc,result);
- break;
- }
- }
-
- NORMAL = old_normal;
- HILITE = old_hilite;
-
- restore_scr();
- }
-
- /* main ********************************************************************
-
- *****************************************************************************/
- void main() {
- int field,code;
-
- get_video_setup();
-
- draw_screen();
-
- field = code = 0;
- while (TRUE) {
- do_fields(screen,4,&field,&code);
- if (code == Esc) break;
- switch(field) {
- case 0: /* change intercom's colors */
- set_color("INTERCOM.COM",I_COLOR_LOC);
- break;
- case 1: /* change message's color */
- set_color("MESSAGE.COM",M_COLOR_LOC);
- break;
- case 2: /* change intercom's hotkey */
- set_hotkey("INTERCOM.COM",I_HOTKEY_LOC,I_SHIFT_STATE);
- break;
- case 3: /* change lanpup's hotkey */
- set_hotkey("LANPUP.EXE",L_HOTKEY_LOC,L_SHIFT_STATE);
- break;
- }
- }
- cls();
- }
-